#ifndef _MUSIC_PLAYER_H_
#define _MUSIC_PLAYER_H_

#include "SDL.h"

class MusicPlayer
{
private:
    SDL_AudioDeviceID mDevice;
    SDL_AudioSpec mSpec;
    Uint8 *mDataBuffer;               /* Pointer to wave data */
    Uint32 mDataLen;            /* Length of wave data */
    Uint32 mCurrentPos;               /* Current play position */

    static void  callback(void *music_player, Uint8 * stream, int len);

public:
    MusicPlayer() =default;
    explicit MusicPlayer(const char* filename);
    ~MusicPlayer();

    inline Uint8 *getDataBuffer()const {return mDataBuffer;}
    inline Uint32 getDataLen()const {return mDataLen;}
    inline SDL_AudioSpec getSpec() const {return mSpec;}
    inline SDL_AudioDeviceID getDeviceID() const {return mDevice;}
    inline Uint32 getCurrentPos()const {return mCurrentPos;}

    inline void setCurrentPos(int newpos) {mCurrentPos = newpos;}

    void play() {SDL_PauseAudioDevice(mDevice, SDL_FALSE); }
    void pause() {SDL_PauseAudioDevice(mDevice, SDL_TRUE); }

};

#endif